const jwt = require("jsonwebtoken"); //引入jwt包
const secret = "vue3-cms";

let encrypt = (data, time) => {
  return jwt.sign(data, secret, { expiresIn: time });
};

let decrypt = token => {
  try {
    let data = jwt.verify(token, secret);
    return {
      info: data,
      token: true,
    };
  } catch (err) {
    return {
      info: err,
      token: false,
    };
  }
};

module.exports = {
  //将这两个加密函数和解密函数导出去
  encrypt,
  decrypt,
};
